package io.zhengsh.nio.datagramchannel;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;

public class DatagramChannelDemo {

	public static void main(String[] args) throws IOException {
		DatagramChannel server = DatagramChannel.open();
		server.socket().bind(new InetSocketAddress(25000));

		ByteBuffer receiveBuffer = ByteBuffer.allocate(64);
		receiveBuffer.clear();
		SocketAddress receiveAddr = server.receive(receiveBuffer);

		DatagramChannel server1 = DatagramChannel.open();
		ByteBuffer sendBuffer = ByteBuffer.wrap("client hello!".getBytes());
		server1.send(sendBuffer, new InetSocketAddress("127.0.0.1", 25000));
	}
}
